<template>
	<view class="box" v-if="isShow">
		<image src="https://www.yongshantuan.cn/images/yongshan/jiantou.png" alt=""></image>
		<view>请点击此处</view>
		<view>使用默认浏览器打开</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				isShow: true
			}
		},
		onLoad(options) {
			let nowDate = new Date();
			let year = nowDate.getFullYear();
			let month = nowDate.getMonth() + 1;
			let day = nowDate.getDate();
			let hour = nowDate.getHours();
			let minute = nowDate.getMinutes();
			let secound = nowDate.getSeconds();
			let dateStr =
				`${year}${month>9?month:'0'+month}${day>9?day:'0'+day}${hour>9?hour:'0'+hour}${minute>9?minute:'0'+minute}${secound>9?secound:'0'+secound}`

			let {
				merchantId,
				token,
				storeName
			} = options;
			if (navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == "micromessenger") {
				this.isShow = true
			} else {
				this.isShow = false
				uni.request({
					url: getApp().globalData.BASE_URL + '/hc/hcOrderMerchant/exportXlsGlobalPage',
					method: 'get',
					data: {
						merchantId
					},
					header: {
						'X-Access-Token': token,
					},
					success(res) {
						console.log('res',res);
						let link = document.createElement('a')
						link.style.display = 'none'
						link.href = res.data;
						link.click()
						document.body.removeChild(link); //下载完成移除元素
						window.URL.revokeObjectURL(url); //释放掉blob对象
						return;
						// let url = window.URL.createObjectURL(new Blob([res.data], {
						// 	type: 'application/vnd.ms-excel',
						// }))
						// let link = document.createElement('a')
						// link.style.display = 'none'
						// link.href = url
						// link.setAttribute('download', storeName+'-' + dateStr + '.xls')
						// document.body.appendChild(link)
						// link.click()
						// document.body.removeChild(link); //下载完成移除元素
						// window.URL.revokeObjectURL(url); //释放掉blob对象
					},
					fail(error) {
						console.log('error', error)
					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.box {
		background-color: rgba(0, 0, 0, 0.55);
		height: 100vh;
		width: 100%;

		image {
			width: 35%;
			margin-left: 60%;
			margin-top: 20rpx;
		}

		view {
			margin-top: 20rpx;
			color: #fff;
			text-align: center;
			line-height: 1.5;
			font-size: 32rpx;
		}
	}
</style>
